/*
 * Copyright (c) 2019. ascend 版权所有禁止转载。
 */

package cn.edu.zua.demo15.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 说明：
 *
 * @author ascend
 * 2019/1/28 17:41
 */
public class FlagValidatorClass2 implements ConstraintValidator<FlagValidator2, Object> {
    /**
     * 预定义的values
     */
    private String[] values;

    @Override
    public void initialize(FlagValidator2 constraintAnnotation) {
        this.values = constraintAnnotation.values();
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        boolean valid = false;
        for (String item : values) {
            // 包含即为验证通过
            if (item.equals(value)) {
                valid = true;
                break;
            }
        }
        return valid;
    }
}
